/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-11-21
 * Time: 12:48
 */
class Solution2 {
    public int[] countBits(int n) {
        int[] ans = new int[n+1];
        for(int i = 0 ; i <= n ; i++ ){
            int count = 0;
            while(i != 0){
                i &= (i-1);//干掉最右侧的1
                count++;
            }
            ans[i] = count;
        }
        return ans;

    }
}
public class Test2{
    public static void main(String[] args) {
        Solution2 test2 = new Solution2();
        int[] ret = test2.countBits(2);
        System.out.println(ret.toString());
    }
}
